package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.common.vo.PageResultVo;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.mapper.AdChannelMapper;
import com.itheima.admin.service.AdChannelService;
import org.springframework.stereotype.Service;

@Service

public class AdChannelServiceImpl extends ServiceImpl<AdChannelMapper, AdChannel> implements AdChannelService {


    /**
     * 频道分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public PageResultVo<AdChannel> pageList(ChannelPageRequestDto dto) {
        Page<AdChannel> pageInfo = new Page<>(dto.getPage(), dto.getSize());
        LambdaQueryWrapper<AdChannel> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(dto.getName()),AdChannel::getName,dto.getName());
        lqw.eq(null != dto.getStatus(),AdChannel::getStatus,dto.getStatus());
        page(pageInfo, lqw);

        return PageResultVo.pageResult(dto.getPage(),dto.getSize(),pageInfo.getTotal(),pageInfo.getRecords());
    }

}
